<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        a {
					
            text-decoration: none;
            color: #08a3f1;
        }

        td {
            line-height: 35px;
						font-size: 12px;
        }
    </style>
</head>

<body>
    <table onload="getList()" id="table" border="1"
        style="width:100%;text-align: center;border-collapse: collapse;margin-top: 10px;">
    </table>
</body>
<script>
    function getList() {
        let xhr = new XMLHttpRequest();
        xhr.open('GET', 'http://localhost:3000/emp/searchs', true);
        xhr.send();
        xhr.onload = function () {
            let str = JSON.parse(xhr.responseText);
            let tr_td = `<tr>
                        <td>序号</td>
                        <td>项目名称</td>
                        <td>项目阶段</td>
                        <td>开工时间</td>
                        <td>项目金额</td>
                        <td>项目编号</td>
                        <td>操作</td>     
                     </tr>`;
            for (var i = 0, count = 0; i < str.data.length; i++) {
                let { eid, ename, sex, birthday, salary, deptid } = str.data[i];
                if (sex == 0) {
                    sex = '前期';
                } else if (sex == 1) {
                    sex = '后期';
                }
                let time = new Date(birthday);
                birthday = time.getFullYear() + '/' + ("0" + (time.getMonth() + 1)).slice(-2) + '/' + ("0" + time.getDate()).slice(-2)
                tr_td += `<tr>
                        <td>${i+1}</td>
                        <td>${ename}</td>
                        <td>${sex}</td>
                        <td>${birthday}</td>
                        <td>${salary}</td>
                        <td>${deptid}</td>
                        <td><a href='javascript:del(${eid})'>删除</a>     <a href="">编辑</a>     <a href="">查看</a>   <a href="">送审</a></td>
                    </tr> `
                console.log(eid);
            }
            table.innerHTML = tr_td
        }
    }
    getList()
</script>
<script>
    function del(eid) {
        let xhr = new XMLHttpRequest();
        xhr.open('delete', `http://localhost:3000/emp/del?eid=${eid}`, true);
        xhr.send();
        xhr.onload = function () {
            let str = JSON.parse(xhr.responseText);
            if (str.code === 200) {
                alert('删除成功');
                getList()
            } else {
                alert('删除失败');
            }
        }
    }
</script>

</html>